package com.example.springbootsenior.AOP.manager.user.service.impl;

import com.example.springbootsenior.AOP.manager.user.dao.IUserDao;
import com.example.springbootsenior.AOP.manager.user.pojo.User;
import com.example.springbootsenior.AOP.manager.user.service.IUserService;
import com.example.springbootsenior.druid.annotation.DataSource;
import com.example.springbootsenior.druid.enums.DataSourceType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户管理服务实现类
 */
@Service(value = "userService")
public class UserServiceImpl implements IUserService {
    @Resource
    private IUserDao userDao;

    @DataSource(value = DataSourceType.SLAVE)
    public List<User> list1() {
        return userDao.list1();
    }

    @Override
    public List<User> queryUsers() {
        List<User> list = userDao.queryUsers();
        return list;
    }

    @Override
    @Transactional
    public boolean addUser(User user) {
        return userDao.addUser(user) > 0;
    }

    @Override
    @Transactional
    public User queryUserById(long id) {
        return userDao.queryUserById(id);
    }

    @Transactional
    @Override
    public boolean updateUserById(User user) {
        return userDao.updateUserById(user) > 0;
    }

    @Transactional
    @Override
    public boolean deleteUserById(long id) {
        return userDao.deleteUserById(id) > 0;
    }
}
